<template>
    <div class="detail-container">
        <el-card shadow="always" class="detail-card">
            <!-- 美食图片 -->
            <div class="image-container">
                <img :src="foodItem.image" alt="Food Image" class="food-image" />
            </div>

            <!-- 美食信息 -->
            <div class="food-details">
                <!-- 名称和分类 -->
                <div class="title-container">
                    <h2 class="food-name">{{ foodItem.name }}</h2>
                    <el-tag type="info" class="category-tag">{{ foodItem.category }}</el-tag>
                </div>

                <!-- 评分 -->
                <div class="rating">
                    <span>评分：</span>
                    <el-rate v-model="foodItem.rating" disabled></el-rate>
                    <span class="rating-value">{{ foodItem.rating.toFixed(1) }}</span>
                </div>

                <!-- 主要信息 -->
                <div class="info-section">
                    <div class="info-item">价格：<span class="highlight">￥{{ foodItem.price }}</span></div>
                    <div class="info-item">辣度：<el-tag type="danger">{{ foodItem.spice_level }}</el-tag></div>
                    <div class="info-item">烹饪时间：<span>{{ foodItem.cooking_time }}</span></div>
                </div>

                <!-- 食材 -->
                <div class="ingredients">
                    <span>主要食材：</span>
                    <div class="ingredient-tags">
                        <el-tag v-for="ingredient in foodItem.ingredients" :key="ingredient" class="ingredient-tag">
                            {{ ingredient }}
                        </el-tag>
                    </div>
                </div>

                <!-- 描述 -->
                <p class="description">{{ foodItem.description }}</p>

                <!-- 购买按钮 -->
                <el-button @click="toback" type="primary" icon="el-icon-shopping-cart-full" class="buy-button" round>
                    返回主页
                </el-button>
            </div>
        </el-card>
    </div>
</template>

<script setup>
import { ref } from "vue";

import { useRoute, useRouter } from "vue-router";
const route = useRoute()
const router = useRouter()

const { query } = route
const toback = () => {
    router.push('/food-index')
}

//从本地存储中获取数据在进行查找
const localData = JSON.parse(localStorage.getItem("sys_foot"))
const foot = localData.find(item => item.id == query.footId)

console.log(foot);


const foodItem = ref({
    id: foot.id,
    name: foot.name,
    category: foot.category,
    ingredients: foot.ingredients,
    description: foot.description,
    price: foot.price,
    image: foot.image,
    rating: foot.rating,
    cooking_time: foot.cooking_time,
    spice_level: foot.spice_level
});
</script>

<style scoped>
.detail-container {
    max-width: 800px;
    margin: 20px auto;
    padding: 20px;
    background-color: #f9f9f9;
}

.detail-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 30px;
    border-radius: 12px;
    box-shadow: 0 6px 18px rgba(0, 0, 0, 0.1);
    background-color: #ffffff;
}

.image-container {
    width: 100%;
    max-width: 500px;
    margin-bottom: 25px;
    overflow: hidden;
    border-radius: 12px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.food-image {
    width: 100%;
    height: auto;
    transition: transform 0.3s ease;
}

.food-image:hover {
    transform: scale(1.05);
}

.food-details {
    width: 100%;
    text-align: center;
}

.title-container {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    margin-bottom: 10px;
}

.food-name {
    font-size: 2em;
    font-weight: bold;
    color: #333;
    margin-bottom: 5px;
}

.category-tag {
    font-size: 1em;
    padding: 5px 10px;
}

.rating {
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 15px 0;
}

.rating-value {
    margin-left: 5px;
    font-weight: bold;
    color: #f56c6c;
}

.info-section {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 20px;
    font-size: 1.2em;
    margin-top: 15px;
}

.info-item {
    font-weight: bold;
}

.highlight {
    color: #ff5722;
}

.ingredients {
    margin-top: 15px;
    font-size: 1em;
}

.ingredient-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: center;
    margin-top: 5px;
}

.description {
    margin: 20px 0;
    font-size: 1.1em;
    color: #606266;
    line-height: 1.5;
}

.buy-button {
    margin-top: 20px;
    background-color: #409eff;
    color: #fff;
    font-size: 1.1em;
    padding: 10px 30px;
    border-radius: 50px;
    box-shadow: 0 4px 12px rgba(64, 158, 255, 0.4);
    transition: all 0.3s ease;
}

.buy-button:hover {
    background-color: #66b1ff;
}
</style>